home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 9.8 KB | 341 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Tracker.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Table.hpp"
-
- #ifndef TRACKER_H
- #include "Tracker.h"
- #endif
-
- #ifndef VIEW_H
- #include "View.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef VIEW_H
- #include "View.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- // ----- OpenDoc Layer -----
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDragAndDrop_xh
- #include <DragDrp.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfTable
- #endif
-
- //========================================================================================
- // class CTableDropTracker
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTableDropTracker::CTableDropTracker
- //----------------------------------------------------------------------------------------
-
- CTableDropTracker::CTableDropTracker(Environment* ev,
- CTablePart* part,
- CTablePartContent* content,
- CTableView* view,
- ODFacet* facet,
- const CCell& sourceCell) :
- FW_CDropTracker(ev, view, facet, TRUE),
- fTableView(view),
- fTablePart(part),
- fTableContent(content),
- fSourceCell(sourceCell),
- fCurCell(-1, -1)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableDropTracker::~CTableDropTracker
- //----------------------------------------------------------------------------------------
-
- CTableDropTracker::~CTableDropTracker()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableDropTracker::ShouldHilite
- //----------------------------------------------------------------------------------------
- // Because I don't want to drop on a cell already containing a proxy
-
- FW_Boolean CTableDropTracker::ShouldHilite(Environment* ev, const FW_CPoint& point, CCell& cell)
- {
- return (fTableContent->HitTest(ev, point, cell) == kTLCell) && (fTableContent->CellToProxy(cell) == NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableDropTracker::BeginTracking
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CTableDropTracker::BeginTracking(Environment* ev,
- const FW_CPoint& anchorPoint)
- {
- CCell cell;
-
- if (ShouldHilite(ev, anchorPoint, cell))
- Hilite(ev, cell, GetFacet(ev));
-
- return anchorPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableDropTracker::ContinueTracking
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CTableDropTracker::ContinueTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& previousPoint,
- const FW_CPoint& currentPoint)
- {
- FW_UNUSED(anchorPoint);
- FW_UNUSED(previousPoint);
- CCell cell;
- if (ShouldHilite(ev, currentPoint, cell))
- Hilite(ev, cell, GetFacet(ev));
- else
- {
- fCurCell = CCell(-1, -1);
- this->HideDragHilite(ev);
- }
-
- return currentPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableDropTracker::Hilite
- //----------------------------------------------------------------------------------------
-
- void CTableDropTracker::Hilite(Environment* ev, const CCell& cell, ODFacet* facet)
- {
- if (cell == fCurCell)
- return;
-
- fCurCell = cell;
-
- #ifdef FW_BUILD_MAC
- this->HideDragHilite(ev);
-
- FW_CWindowContext gc(ev, facet); // focus drawing to the window
-
- if (cell != fSourceCell)
- {
- FW_CRect cellRect;
- fTableContent->FindRect(cell, cellRect);
-
- FW_CRect shapeBounds = fTableView->GetBoundsInContent(ev);
- cellRect.Intersection(shapeBounds);
- fTableView->ViewContentToFrame(ev, cellRect);
-
- FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, cellRect);
-
- this->ShowDragHilite(ev, aqShape, TRUE);
- }
- #endif
- }
-
- //========================================================================================
- // class CGridLineTracker
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CGridLineTracker constructor
- //----------------------------------------------------------------------------------------
- CGridLineTracker::CGridLineTracker(Environment* ev,
- FW_CView* view,
- ODFacet* facet,
- ETableLoc tl,
- FW_CRect dragArea,
- FW_CPoint borders) :
- FW_CTracker(ev, view, facet),
- fDragArea(dragArea),
- fOldBorders(borders),
- fNewBorders(borders),
- fCross(borders, dragArea.BotRight())
- {
- // Get direction of resize
- fHorizMove = ((tl & (kTLLeftBorder + kTLRightBorder)) != 0);
- fVertMove = ((tl & (kTLTopBorder + kTLBottomBorder)) != 0);
-
- if (fHorizMove)
- fCross.SetVLineToMove();
- if (fVertMove)
- fCross.SetHLineToMove();
- }
-
- //----------------------------------------------------------------------------------------
- // CGridLineTracker destructor
- //----------------------------------------------------------------------------------------
- CGridLineTracker::~CGridLineTracker()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CGridLineTracker::BeginTracking
- //----------------------------------------------------------------------------------------
- FW_CPoint CGridLineTracker::BeginTracking(Environment* ev,
- const FW_CPoint& anchorPoint)
- {
- // Display borders that are moving
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
- fCross.Render(vc);
-
- return anchorPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // CGridLineTracker::ContinueTracking
- //----------------------------------------------------------------------------------------
- FW_CPoint CGridLineTracker::ContinueTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& previousPoint,
- const FW_CPoint& currentPoint)
- {
- FW_UNUSED(anchorPoint);
- FW_CPoint now(currentPoint);
-
- // Stay in permissible drag area
- if (now.x < fDragArea.left)
- now.x = fDragArea.left;
- if (now.x > fDragArea.right)
- now.x = fDragArea.right;
- if (now.y < fDragArea.top)
- now.y = fDragArea.top;
- if (now.y > fDragArea.bottom)
- now.y = fDragArea.bottom;
-
- // Move the borders
- if (now != previousPoint)
- {
- FW_Fixed x = (fHorizMove ? now.x - previousPoint.x : FW_IntToFixed(0));
- FW_Fixed y = (fVertMove ? now.y - previousPoint.y : FW_IntToFixed(0));
-
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
- fCross.Render(vc);
- fCross.MoveShape(x, y);
- fCross.Render(vc);
-
- fNewBorders.x += x;
- fNewBorders.y += y;
- }
-
- return now;
- }
-
- //----------------------------------------------------------------------------------------
- // CGridLineTracker::EndTracking
- //----------------------------------------------------------------------------------------
- FW_Boolean CGridLineTracker::EndTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& lastPoint)
- {
- // Restore the borders
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
- fCross.Render(vc);
-
- return anchorPoint != lastPoint;
- }
-
- //========================================================================================
- // class CCrossShape
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CCrossShape::CCrossShape
- //----------------------------------------------------------------------------------------
-
- CCrossShape::CCrossShape(const FW_CPoint& brCell, FW_CPoint& brFrm)
- : vLine(brCell.x, FW_kFixed0, brCell.x, brFrm.y),
- hLine(FW_kFixed0, brCell.y, brFrm.x, brCell.y)
- {
- vLine.SetInk(FW_kInvertInk);
- hLine.SetInk(FW_kInvertInk);
-
- vLine.SetRenderVerb(FW_kNoRendering);
- hLine.SetRenderVerb(FW_kNoRendering);
- }
-
- //----------------------------------------------------------------------------------------
- // CCrossShape::Render
- //----------------------------------------------------------------------------------------
-
- void CCrossShape::Render(FW_CGraphicContext& graphicContext)
- {
- vLine.Render(graphicContext);
- hLine.Render(graphicContext);
- }
-
- //----------------------------------------------------------------------------------------
- // CCrossShape::MoveShape
- //----------------------------------------------------------------------------------------
-
- void CCrossShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
- {
- vLine.MoveShape(deltaX, FW_IntToFixed(0));
- hLine.MoveShape(FW_IntToFixed(0), deltaY);
- }
-
- //----------------------------------------------------------------------------------------
- // CCrossShape::SetHLineToMove
- //----------------------------------------------------------------------------------------
-
- void CCrossShape::SetHLineToMove()
- {
- hLine.SetRenderVerb(FW_kFrame);
- }
-
- //----------------------------------------------------------------------------------------
- // CCrossShape::SetVLineToMove
- //----------------------------------------------------------------------------------------
-
- void CCrossShape::SetVLineToMove()
- {
- vLine.SetRenderVerb(FW_kFrame);
- }
-
-
-